home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 352_01 / fullflnm.cpp < prev    next >
C/C++ Source or Header  |  1991-04-28  |  1KB  |  52 lines

  1. // FULLFLNM.CPP
  2. // make_fullfilename ()
  3. //        routine to catenate directory, filename, and extension
  4. //        and make sure that there are the right number of \, ., etc...
  5. //        (does not cover all possible invalid constructions,
  6. //            but allows things like:  C:\  +  \rootfile.ex1  + .ex2)
  7. //     
  8. #include "dblib.h"
  9. String *make_fullfilename ( char *dir, char *fn, char *ext )
  10.     {
  11.     String *Sdne = new String;
  12.     
  13.     *Sdne = dir;
  14.     if ( Sdne->len() > 0 ) 
  15.         {
  16.         (*Sdne).trim ( "\\" );
  17.         (*Sdne) += "\\";            // ensures exactly one terminal \
  18.         }
  19.  
  20.     String Sfn = fn;    
  21.     if ( ext != NULL )
  22.         {
  23.         int ndot = Sfn.find ( "." );
  24.         if ( ndot >= 0 )         // if dot is present...
  25.             {
  26.             Sfn.cut ( ndot );        // remove && force to extension given
  27.             }
  28.         if ( ext[0] != '.' ) Sfn += ".";
  29.         Sfn += ext;
  30.         }    
  31.         
  32.     *Sdne += Sfn;     
  33.     
  34.     return Sdne;        // directory_name_extension ()
  35.     }
  36.     
  37. #if 0
  38. // code for testing above routine.    
  39. main (int argc, char **argv)
  40.     {
  41.     char *d=NULL, *n=NULL, *e=NULL;
  42.     
  43.     if ( argc > 3 ) e=argv[3];
  44.     if ( argc > 2 ) n=argv[2];
  45.     if ( argc > 1 ) d=argv[1];
  46.     
  47.     String *S = make_fullfilename ( d,n,e );
  48.     puts ( *S );
  49.     delete S;
  50.     return 0;    
  51.     }
  52. #endif /* 0 - end of test code */